package com.hefeng.example.config;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice   //定义全局异常的处理类    返回值JSON串
public class MyExceptionAdvice {
    @ExceptionHandler(CommonException.class)
    @ResponseBody
    public JSONObject CommonExceptionHandler(CommonException e) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",e.getCode());
        jsonObject.put("msg",e.getMsg());
        return jsonObject;
    }

    }


